package root.plumbum2;

import java.util.Date;
import java.util.List;
import java.util.Random;

import root.repositorios.RepositorioInteresse;
import root.repositorios.RepositorioInterface;


public class Item {

	private String name;
	private String description;
	private String category;
	private String IDItem;
	private Date date = new Date();
	private String dono;
	//private String pedinte="nenhum";
	private RepositorioInterface<Interesse> repositorioInteresse;
	
	
	public Item(String name, String description, String category, String dono)throws Exception {
		Random random = new Random();
		if (!VerificadorDadosEntrada.stringValida(name)) {
			throw new Exception("Nome inválido");
		} else if (!VerificadorDadosEntrada.stringValida(category)) {
			throw new Exception("Categoria inválida");
		}
		
		this.dono = dono;
		
		
		this.name = name;
		this.description = description;
		this.category = category;
		this.IDItem = this.date.toString()+String.valueOf((int) (random.nextFloat() * 100000))+this.name+this.description+this.category;
		this.repositorioInteresse = new RepositorioInteresse();
		
	}


//	public void setPedinte(String pedinte){
//		this.pedinte=pedinte;
//	}
//	public String getPedinte(){
//		return this.pedinte;
//	}
	
	
	public String getDono(){
		return this.dono;
	}
	
	public String getIDItem() {
		return this.IDItem;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the category
	 */
	public String getCategory() {
		return category;
	}

	/**
	 * @param category the category to set
	 */
	public void setCategory(String category) {
		this.category = category;
	}

	public String getAtributo(String atributo) {
		String retorno = "";
		if (atributo.equals("nome"))
			retorno = getName();
		else if (atributo.equals("categoria"))
			retorno = getCategory();
		else if (atributo.equals("descricao"))
			retorno = getDescription();
		return retorno;
	}
	
	public RepositorioInterface<Interesse> getRepositorioInteresses(){
		return repositorioInteresse;
	}
	
	
	/**
	 * Passa as principais caracteristicas do item para uma string
	 */
	@Override
	public String toString() {
		String toString = String.format("%s (%s): %s", name, category, description);
		return toString;
	}

}
